package cn.truistic.enmicromsg.wx.wx_keysendmessage;

import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import cn.truistic.enmicromsg.R;
import cn.truistic.enmicromsg.base.BaseActivity;
import cn.truistic.enmicromsg.common.dialog.ContentDialog;
import cn.truistic.enmicromsg.common.interfaces.DialogContentCallback;
import cn.truistic.enmicromsg.common.util.PreferenceHelper;
import cn.truistic.enmicromsg.common.util.WxHeple;
import cn.truistic.enmicromsg.wx.wx_nearby.NearbyActivity;

/**
 * sj:15点39分
 * name ：ts
 * 用途： 自动发消息
 */
public class KeySendMessageActivity extends BaseActivity implements DialogContentCallback {
    private Toolbar mToorbar ;
    private Button mBtnAkeychat;
    private Button mBtnEditAkeychat;
    private TextView tv_Reply_message;
    private ContentDialog contentDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_key_send_message);
        initView();
        initListener();

    }

    private void initListener() {
        mBtnAkeychat.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                PreferenceHelper.commitInt("mSendPeopleNum",30);
                boolean isOpen = isAccessibilitySettingsOn();
                if (isOpen) {
                    new Thread(new Runnable() {
                        @Override
                        public void run() {
                            mEnApplication.setAKeySendMessage(true);  //开启一键发消息// 模块
                            mEnApplication.setAllowAKeySendMessage(true);
                            WxHeple.execShellCmd("am force-stop com.tencent.mm");
                            WxHeple.execShellCmd("input keyevent 3");
                            sleepMiss(2500);
                            WxHeple.intentWechat(mContext);//开启微信
                        }
                    }).start();
                }
            }
        });
        //输入
        mBtnEditAkeychat.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                contentDialog.show();
            }
        });
    }

    private void initView() {
        mToorbar = (Toolbar) findViewById(R.id.main_toolbar);
        mBtnAkeychat = (Button) findViewById(R.id.btn_akeychat);
        mBtnEditAkeychat = (Button) findViewById(R.id.btn_edit_akeychat);//输入回复消息
        tv_Reply_message = (TextView) findViewById(R.id.tv_Reply_message);
        setSupportActionBar(mToorbar);
        contentDialog = new ContentDialog(KeySendMessageActivity.this, KeySendMessageActivity.this);
        String content = PreferenceHelper.getString( "OneKeyDialogText" , "" ); //存content 带sp
        if (!TextUtils.isEmpty(content)){
            tv_Reply_message.setText("回复内容; "+ content);
        }
    }

    @Override
    public void Negative() {
        contentDialog.cancel(); //取消
    }

    @Override
    public void Positive( String content ) {
        tv_Reply_message.setText("回复内容; "+ content );
        PreferenceHelper.commitString( "OneKeyDialogText" , content ); //存content 带sp
    }
}
